package com.bulls.demo.hrmsdemo.ib;

import java.util.ArrayList;

import javax.persistence.EntityManager;

import com.bulls.demo.hrmsdemo.dao.EmployeeDAO;
import com.bulls.demo.hrmsdemo.dao.EmployeeDAOImpl;
import com.bulls.demo.hrmsdemo.db.Employee;
import com.bulls.demo.hrmsdemo.db.EmployeeExperience;
import com.bulls.demo.hrmsdemo.db.EmployeeQualification;
import com.bulls.demo.hrmsdemo.vo.EmployeeVO;

public class EmployeeLogic {
	
	static EmployeeDAO employeeDAO;
	public static EmployeeDAO getDAO(){
		EmployeeDAOImpl employeeDAOImpl = new EmployeeDAOImpl();
		employeeDAO = employeeDAOImpl;
		return employeeDAO;
	}

	public static EmployeeVO save(EmployeeVO employeeVO,
			EntityManager entityManager) {
		Employee employee  = new Employee();
		ArrayList<EmployeeExperience> employeeExperiences = new ArrayList<EmployeeExperience>();
		ArrayList<EmployeeQualification> employeeQualifications = new ArrayList<EmployeeQualification>();
		employee = employeeVO.getEmployee();
		employee = getDAO().save(employee, entityManager);
		employeeQualifications = employeeVO.getEmployeeQualifications();
		if(employeeQualifications!=null)
		employeeQualifications = getDAO().saveQualification(employeeQualifications,entityManager);
		employeeExperiences = employeeVO.getEmployeeExperiences();
		if(employeeExperiences!=null)
		employeeExperiences = getDAO().saveExperience(employeeExperiences,entityManager);
		employeeVO.setEmployee(employee);
		employeeVO.setEmployeeQualifications(employeeQualifications);
		employeeVO.setEmployeeExperiences(employeeExperiences);
		return employeeVO;
	}

	public static EmployeeVO search(Long long1, EntityManager entityManager) {
		employeeDAO = getDAO();
		EmployeeVO  employeeVO = new EmployeeVO();
		employeeVO = employeeDAO.search(long1,entityManager);
		return employeeVO;
	}

	public static boolean delete(String employeeID, EntityManager entityManager) {
		employeeDAO = getDAO();
		boolean boo  = employeeDAO.delete(employeeID,entityManager);
		return boo;
	}

}
